package com.xiedafeng.www.view;

import com.xiedafeng.www.controller.RemarkController;
import com.xiedafeng.www.po.Event;
import com.xiedafeng.www.po.Remark;
import com.xiedafeng.www.po.User;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class CreateRemarkView {
    TextField remarkContent =new TextField();
    Stage stage=new Stage();
    public void create(User user, Event event){
        GridPane gridPane=new GridPane();
        Text tip=new Text("评论");
        Button confirm=new Button("确定");
        confirm.setOnMouseClicked(event1 -> {
            try {
                confirmButton(user,event);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        gridPane.add(tip,0,0);
        gridPane.add(remarkContent,0,1);
        gridPane.add(confirm,0,2);
        gridPane.setAlignment(Pos.CENTER);
        Scene scene=new Scene(gridPane);
        stage.setScene(scene);
        stage.showAndWait();
    }
    private void confirmButton(User user, Event event) throws Exception {
        Remark remark=new Remark();
        remark.setRemarkContent(remarkContent.getText());
        RemarkController remarkController=new RemarkController();
        remarkController.createRemark(user,event,remark);
        stage.close();
    }
}
